<template>
  <van-dialog v-model:show="show" :show-confirm-button="false">
    <template #title>
      选择库位
    </template>
    <div style="display: flex;flex-direction: row; justify-content: center; align-items: center; width:100%;" >
      <van-search
        v-model="search"
        placeholder="请输入搜索关键词"
      />
      <van-icon name="scan" color="blue" size="50" @click="scanCode"/>
    </div>

    <van-cell v-for="item in resData" @click="onChoose(item.sWarehouseNumber)">
      <template #title>
        {{item.sWarehouseNumber}}</template>
      <template #label>
        <van-row v-for="itemss in item.regulation">
          <van-tag >{{itemss.sRegulationNames.replaceAll('"','')}}</van-tag>
        </van-row>
      </template>
      <template #value>
        <van-row justify="end">{{item.sDescribe}}</van-row>
        <van-row justify="end">{{item.sPosition}}</van-row>
      </template>
    </van-cell>
    <van-row v-show="resData.length==0"  justify="center" style="height:60px; background-color: #969799" align="center">
      暂无搜索库位

    </van-row>
  </van-dialog>
</template>
<script setup >


  import {queryWarehouse} from "@/api/Base/repositoryManager.ts";
  let search =ref("");
  let resData=ref([
    {
      "sWarehouseNumber": "w23",
      "sPosition": "21321312312",
      "sDescribe": "2213213",
      "sColor": "#C53030",
      "sParentNumber": "null",
      "bTemp": 0,
      "dUpdateDatetime": "2025-01-17T03:22:32.000+00:00",
      "dCreateDatetime": "2025-01-17T03:22:32.000+00:00",
      "regulation": [
        {
          "sWarehouseNumber": "w23",
          "nRegulationIds": "[3768,3769,3771]",
          "sRegulationNames": "[\"电阻\",\"0402\",\"1\"]"
        }
      ],
      "child": []
    }
  ]);

  onMounted(()=>{
    queryData()
  })
  watch(search,()=>{
    queryData();
  })
  async function scanCode(){
    let code=await pro.scannerCode();
    search.value=code;
  }
  let emit=defineEmits(["chooseEvent"]);
  function onChoose(  wareHouseNumber){
      emit("chooseEvent",wareHouseNumber);
      show.value=false
      search.value="";

  }
  let show=ref(false)
  function queryData(){
    queryWarehouse({
      "page": 1,
      "pageSize": 999999,
      "searchWarehouseNumber": search.value,
      "searchDescribeOrRegulation": "",
      "searchDescribe": "",
      "searchPosition": "",
      "searchType": 0
    }).then(d=>{
        resData.value=d.data.list;
    })
  }
  defineExpose({
    //传料号,来判定推荐库位和之前的库位 和推荐库位
    apply:function (materielNo){
      //todo 推荐库位没有写
      queryData();
      show.value=true;
    }
  })

</script>
<style scoped lang="less">

</style>